<?php 
namespace App\Http\Controllers\Admin;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Model\Cate;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Illuminate\Support\Facades\DB;
class CateController extends CommonController {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function add(Request $request)
	{
		if($request->isMethod('post')){
			Cate::ad($request,$this); //验证提交数据
			$pid = intval($_POST['pid']);
			$cate = strval($_POST['cate']);
			$id = DB::table('cate')->insertGetId(
			 ['pid' => $pid,'name' => $cate]);  //添加数据
			if(!$id){
				echo '添加失败';
				return back();
			}else{
				echo '添加成功';
				return back();
			}
		}



		$data = DB::table('cate')->get(); //获取所有数据
		$arr = $this->digui($data,0);
	    return	view('Admin/cate',['data' => $arr]);
	}


	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		//
	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		//
	}

	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}

}
